using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.Api.Demain.ContentManagement;
using RBAC.Api.Erroc;
using RBAC.Api.Read.Command.ContentManagement;
using RBAC.Api.Read.Dto;

namespace RBAC.Api.Read.Controllers.ContentManagement
{
    /// <summary>
    /// 科室管理控制器--读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        public DepartmentController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 显示科室列表
        /// </summary>
        /// <param name="hospitalId">医院ID</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPagin<DepartmentModel>>> ShowDepartments(
            long? parentId = null, 
            int pageIndex = 1, 
            int pageSize = 10)
        {
            ShowDepartmentsCommand command = new ShowDepartmentsCommand();
            command.ParentId = parentId;
            command.PageIndex = pageIndex;
            command.PageSize = pageSize;
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取科室树形结构（用于下拉选择等）
        /// </summary>
        /// <param name="hospitalId">医院ID，为空时获取所有医院的科室</param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<CascadeItem>>> GetDepartmentTree(long? hospitalId = null)
        {
            GetDepartmentsCommand command = new GetDepartmentsCommand();
            return mediator.Send(command);
        }
    }
}